package fr.afcepf.atod19.authentification.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.atod19.authentification.entities.Account;

public class DAOAuthentification implements IDAOAuthentification {
	
	@PersistenceContext
	private EntityManager entityManager;


	public boolean authentifier(String login, String password) {
		
		boolean authent = false;
		Query query =entityManager.createQuery("from Account as u where u.login=:login and u.password=:password");
		query.setParameter("login", login);
		query.setParameter("password", password);
		List<Account> accounts = query.getResultList();
		if (accounts.size() != 0){
			authent = true;
		}
		return authent;
	}

}
